package com.jnu.testdrivendevelopment.data;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

public class CirleSpriter {
    float x,y, radius,maxWidth,maxHeight;
    double direction;

    public CirleSpriter(float x,float y,float radios,float maxWidth,float maxHeight){
        this.x=x;
        this.y=y;
        this.radius =radios;
        this.direction=Math.random();
        this.maxWidth=maxWidth;
        this.maxHeight=maxHeight;
    }
    public void draw(Canvas canvas){
        Paint paint=new Paint();
        paint.setColor(Color.RED);

        canvas.drawCircle(x,y,radius,paint);
    }
    public void move(){
        this.x+=20+Math.cos(direction);
        this.y+=20+Math.sin(direction);
        if(this.x<0) this.x+=maxWidth;
        if(this.y<0) this.y+=maxHeight;
        if(this.x>maxWidth) this.x-=maxWidth;
        if(this.y>maxHeight) this.y-=maxHeight;
    }
    public boolean isShot(float touchedX,float touchedY){
        double distance=(touchedX-this.x)*(touchedX-this.x)+(touchedY-this.y)*(touchedY-this.y);
        return (Math.abs(distance-radius*radius)<1e-7);
    }
}
